﻿using System;
using System.IO;

namespace ODM_AddIn
{
    public class AlternativeSelectBox : ESRI.ArcGIS.Desktop.AddIns.ComboBox
    {
        private string inputPath;
        private string currZone = "";
        //private bool stopUpdate = false;

        public AlternativeSelectBox()
        {
        }

        protected override void OnUpdate()
        {
            if (ODM_Code.rUtils.CheckInit())
            {
                if (!currZone.Equals(ConfigSettings.ReadSetting("analysisArea")))
                {
                    this.Clear();
                    currZone = ConfigSettings.ReadSetting("analysisArea");

                    inputPath = "C:\\magfire\\" + ConfigSettings.ReadSetting("analysisArea") + "\\input";

                    if (Directory.Exists(inputPath))
                    {
                        string[] files = System.IO.Directory.GetDirectories(inputPath);
                        foreach (string s in files)
                        {
                            string[] spl = s.Split('\\');
                            int i = spl.Length;

                            string addThis = spl[i - 1];
                            if (addThis.StartsWith("S"))
                            {
                                this.Add(spl[i - 1]);
                            }
                        }
                    }
                }
            }
        }

        protected override void OnSelChange(int cookie)
        {
            try
            {
                Item it = this.GetItem(cookie);
                string alternativeName = it.Caption;

                ConfigSettings.WriteSetting("currentAlternative", alternativeName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "AlternativeSelectBox OnSelChange");
            }
        }

        
    }

}
